﻿/*
SINACOR - BMF&Bovespa
Arquivo: Operador.cs
Criado em: 27-nov-2009 11:59:19
Arquiteto Responsável: ramelo.7comm
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.ServiceModel;
using System.Text;
using Sinacor.Infra.UI.Common;
using Sinacor.Infra.UI.Security.Services;
using Sinacor.UI.Bovespa.Alocacao.Communication.Bovespa.Alocacao.CoberturaTermo;
using Sinacor.UI.Bovespa.Alocacao.Communication.Bovespa.Operador.Operador;

namespace Sinacor.UI.Bovespa.Alocacao.Communication
{
    /// <summary>
    /// Class Operador
    /// </summary>
    public class Operador : BaseCommunication
    {

        #region Construtores

        /// <summary>
        /// Construtor padrão
        /// </summary>
        public Operador()
            : base(default(SessionInformation))
        {
        }

        /// <summary>
        /// Construtor parametrizado
        /// </summary>
        /// <param name="sessionInformation"></param>
        public Operador(SessionInformation sessionInformation)
            : base(sessionInformation)
        {
        }
        #endregion Construtores

        #region Métodos

        /// <summary>
        /// ConsultarOperadores
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ModelCollection<Model.Operador> ConsultarOperadores(Model.Parameter.FiltroOperador request)
        {
            ModelCollection<Model.Operador> response = null;
            IOperador servico = null;

            try
            {
                using (ServiceInstance<IOperador> service = new ServiceInstance<IOperador>())
                {
                    servico = service.TryGetInstance(this.Session);
                    request.CodigoOperador = (int?)this.Session.UserId;
                    Translator.DataContractToModel.Operador toOperador =
                        new Translator.DataContractToModel.Operador();

                    Translator.ModelToDataContract.Operador entityRequest =
                        new Translator.ModelToDataContract.Operador();

                    response = toOperador.ToOperador(
                                    servico.ConsultarOperadores(
                                        entityRequest.ToFiltroOperadorRequest(request))
                     );
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
                return null;
            }

            return response;
        }

        /// <summary>
        /// ObterPreferencias
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public Model.Preferencias ObterPreferencias(Int32 request)
        {
            Model.Preferencias response = null;
            IOperador servico = null;

            try
            {
                using (ServiceInstance<IOperador> service = new ServiceInstance<IOperador>())
                {
                    servico = service.TryGetInstance(this.Session);

                    Translator.DataContractToModel.Operador toOperador =
                        new Translator.DataContractToModel.Operador();

                    Sinacor.UI.Bovespa.Alocacao.Communication.Bovespa.Operador.Operador.CodigoOperadorRequest entityRequest =
                        new Sinacor.UI.Bovespa.Alocacao.Communication.Bovespa.Operador.Operador.CodigoOperadorRequest();

                    entityRequest.Valor = request;

                    response =  toOperador.ToPreferencias(
                                    servico.ObterPreferencias(entityRequest)
                     );
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
                return null;
            }

            return response;
        }

        #endregion Métodos
    }
}